package com.wenxixuanwu.fruitstore.controller;

import com.wenxixuanwu.fruitstore.entity.Category;
import com.wenxixuanwu.fruitstore.service.BackCategoryService;
import com.wenxixuanwu.fruitstore.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author :小凡凡
 * @version :1.0
 * @Project :fruitstore
 * @Date :2022/4/26
 */
@RestController
@RequestMapping("/baseCategory")
public class BackCategoryController extends BaseController{

    @Autowired
    private BackCategoryService categoryService;

    @GetMapping("/findCategoryAll")
    public JsonResult<List<Category>> findCategoryAll(){
        List<Category> data = categoryService.findCategoryAll();
        return new JsonResult<>(OK, data);
    }

    @GetMapping ("/insertCategory/{categoryName}")
    public JsonResult<Category> insertCategory(@PathVariable("categoryName") String category){
        Integer data = categoryService.insertCategory(category);
        return new JsonResult<Category>(OK);
    }
    @GetMapping("/deleteCategory/{id}")
    public JsonResult<Void> deleteCategory(@PathVariable("id") Integer id){
        Integer data = categoryService.deleteCategory(id);
        return new JsonResult<Void>(OK);
    }
}
